<template>
	<view>
		<view class="uni-padding-wrap uni-common-pb">
			<view class="uni-hello-text uni-common-pb" style="padding-bottom: 0upx;margin-top: 20upx;">
				{{year}}年{{month}}月{{day}}日,金额合计：{{amtSum}}元，费用合计：{{costSum}}
			</view>
			<view class="uni-card">
				<view class="uni-list">
					<view class="uni-list-cell uni-collapse" v-for="(item,index) in costList" :key="index">
						<view class="uni-list-cell-navigate uni-navigate-right" hover-class="uni-list-cell-hover"
						@click="toCostDetail(item)"
						>
							金额{{item.amt}}元 | 费用{{item.cost}} 元
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				year:'',
				month:'',
				day:'',
				costList:[],
				amtSum:0,
				costSum:0,
			}
		},
		onLoad(options) {
			this.year = options.year;
			this.month = options.month;
			this.day = options.day;
			// console.log(this.day);
		},
		onShow() {
			const that = this;
			this.$net.getTradeDayDetailList({
				year:this.year,
				month:this.month,
				day:this.day,
			}).then(res => {
				if(res.data.length === 0){
					uni.navigateBack({
						delta:1
					})
				}
				that.amtSum = 0;
				that.costSum = 0;
				for (let item of res.data) {
					that.amtSum += parseFloat(item.amt);
					that.costSum += parseFloat(item.cost);
				}
				that.costList = res.data;
			})
		},
		methods:{
			toCostDetail(item){
				uni.navigateTo({
					url:`/pages/index/edit?id=${item.id}&amt=${item.amt}&transDate=${item.transDate}`
				})
			},
		}
	}
</script>

<style>
	page {
		height: auto;
		min-height: 100%;
		background-color: #EBEBEB;
	}
	
	.uni-card {
		box-shadow: none;
	}
	
	.uni-list:after {
		height: 0;
	}
	
	.uni-list:before {
		height: 0;
	}
	
	.uni-hello-text {
		word-break: break-all;
	}
</style>
